function OrthoTemp_CardLSDCommon(CurveVsTempCAE,iConst,iPrefix, isMID)
{ 
// iPrefix 0 = density curve, 1 = GEVsTemp curve.
	var length = 10;
	var s = "";
	if(!isMID)
		s += convertToFixedLengthString(iConst, length);
	else{
		s+= writeMID(length, iConst);
	}
	
	var zeroStr = convertToFixedLengthString(0.0, length);
	if(CurveVsTempCAE != null && CurveVsTempCAE[1][0] != null)
	{
	if(iPrefix == 0)
	{
		s +=  convertToFixedLengthString(CurveVsTempCAE[1][0], length) + zeroStr + zeroStr + zeroStr + "\n";
		for (var iNum = 0 ; iNum < 6 ;iNum++)
			s += zeroStr;
			s +=  "\n";	
		for (var iNum = 0 ; iNum < 7 ;iNum++)
			s += zeroStr;
			s +=  "\n";	
	}
	else if(iPrefix == 1)
		s += zeroStr + convertToFixedLengthString(CurveVsTempCAE[1][1], length) + "\n";
	}
		
	return s;
}

function writeMID(length, iConst){
	var s="";
	var n = iConst.length(); 
	for (var i =0; i<(length-n); i++){
		s+=" "
	}
	s += iConst ;
	return s;
}

function OrthoTemp_CardLSD(Curves)
{ 
	var length = 10;
	var X = 0;
    var Y = 1;
	var s = "";
	var zeroStr = convertToFixedLengthString(0.0, length);
	var ssn = "\n";
	// curve is a nested array [series][X = 0, Y = 1]

	var iNum = 0;
	var curveRow = Curves[iNum];
	var iRow = curveRow.length;	
	var iTotalCurves = Curves.length;
	var iENUCurves = 6;//Two loops, first for E,Nu second for A,G
	
	if(iTotalCurves < 12)
		return s;
		
	//Write E,NU,
	for(var iNumRow = 0 ; iNumRow < iRow ; iNumRow++)
	{
		for(var i = 0 ; i < iENUCurves ; i++) 
		{			
			var curve = Curves[i];
			if(curve != null)
			s += convertToFixedLengthString(curve[iNumRow][Y], length);
		}
			s += ssn;
	}

	
	//Write A,G,Temp
	for(var iNumRow = 0 ; iNumRow < iRow ; iNumRow++)
	{
		for(var i = iENUCurves ; i < 12 ; i++) 
		{			
			var curve = Curves[i];
			if(curve != null)
			s +=  convertToFixedLengthString(curve[iNumRow][Y], length);
		}
			if(curve != null)
			s += convertToFixedLengthString(curve[iNumRow][X], length);
			s += ssn;
	}
	
	return s;
}

function OrthoTemp_CardLSDThermal(Curves, iConst) {
	var length = 10;
	var s = "";
	var ssZero = convertToFixedLengthString(0.0, length);
	var X = 0;
	var Y = 1;

	var iNum = 0;
	var curveRow = Curves[iNum];
	var iRow = curveRow.length;
	var iTotalCurves = Curves.length;

	for (var iNum = 0; iNum < 6; iNum++) {
		var curve = Curves[iNum];
		if (curve != null) {
			if (iNum == 0) {
				s += writeMID(length, iConst) + ssZero
						+ ssZero + ssZero + ssZero + ssZero + ssZero + "\n";
				for (var iNum1 = 0; iNum1 < iRow; iNum1++)
					s += convertToFixedLengthString(curve[iNum1][0], 10);
				s += "\n";
				for (var iNum1 = 0; iNum1 < iRow; iNum1++)
					s += convertToFixedLengthString(curve[iNum1][1], 10);
				s += "\n";
			} else if (iNum == 1) {
				for (var iNum1 = 0; iNum1 < iRow; iNum1++)
					s += convertToFixedLengthString(curve[iNum1][1], 10);
				s += "\n";
			} else if (iNum == 2) {
				for (var iNum1 = 0; iNum1 < iRow; iNum1++)
					s += convertToFixedLengthString(curve[iNum1][1], 10);
				s += "\n";
			} else if (iNum == 3) {
				for (var iNum1 = 0; iNum1 < iRow; iNum1++)
					s += convertToFixedLengthString(curve[iNum1][1], 10);
				s += "\n";
			}
		} else {
			if (iNum == 3) {
				for (var iNum1 = 0; iNum1 < 8; iNum1++)
					s += ssZero;
				s += "\n";

			}
		}

		if (iNum == 4) {
			for (var iNum1 = 0; iNum1 < 6; iNum1++)
				s += ssZero;
			s += "\n";
		}
		if (iNum == 5) {
			for (var iNum1 = 0; iNum1 < 3; iNum1++)
				s += ssZero;
			s += "\n";
		}
	}

	return s;
}
